from django.db.models import JSONField  # NOQA
from django.db import models

from utils.xss_filter import XSSHtml


class RichTextField(models.TextField):
    # 将模型实例保存到数据库时,Django 会调用每个字段的 get_prep_value 方法。
    # 基于此实现 对非法字符过滤
    def get_prep_value(self, value):
        with XSSHtml() as parser:
            return parser.clean(value or "")
